import { EggAppConfig, EggAppInfo, PowerPartial } from 'midway';

export type DefaultConfig = PowerPartial<EggAppConfig>
const path = require('path');
export default (appInfo: EggAppInfo) => {
  const config = {
    security: {
      csrf: {
        enable: false,
        ignoreJSON: true,
      },
      domainWhiteList: ['*'],
    },
  } as DefaultConfig;

  // use for cookie sign key, should change to your own and keep security
  config.keys = appInfo.name + '_{{keys}}';
  config.io = {
    init: { }, // passed to engine.io
    namespace: {
      '/': {
        connectionMiddleware: ['auth'],
        packetMiddleware: [],
      },
    },
  }
config.jwt = {
    secret: "123456"//自定义 token 的加密条件字符串
  };
//不需要验证token的路由
config.routerAuth = ['/user/login','/getPhone','/getFiles']
​exports.aliyunSms = {
};
config.multipart = {
  // fileSize: '50mb',  // 文件大小
  fileModeMatch: /^(\/tools\/excel\/import)$/, // '/tools/excel/import'接口使用file模式，其他使用stream模式
  fileExtensions: ['.xlsx', '.xls'],
}
 // add your middleware config here
config.middleware = ['errorHandle'];//中间件执行顺序则是按照数组中的顺序执行

config.static = {
  // 静态化访问前缀,如：`http://127.0.0.1:7001/static/images/logo.png`
  prefix: '/static', 
  dir: path.join(appInfo.baseDir, 'app/public'), // `String` or `Array:[dir1, dir2, ...]` 静态化目录,可以设置多个静态化目录
  dynamic: true, // 如果当前访问的静态资源没有缓存，则缓存静态文件，和`preload`配合使用；
  preload: false,
  maxAge: 31536000, // in prod env, 0 in other envs
  buffer: true, // in prod env, false in other envs
};
// exports.session = {
//   key: 'EGG_SESS',
//   maxAge: 1000*60*5,
//   httpOnly: true,
//   encrypt: true
// }
  // exports.knex = {
  //   // database configuration
  //   client: {
  //     // database dialect
  //     dialect: 'postgresql',
  //     connection: {
  //       // host
  //       host: '127.0.0.1',
  //       // port
  //       port: 5432,
  //       // username
  //       user: 'postgres',
  //       // password
  //       password: '123456',
  //       // database
  //       database: 'chat',
  //     },
  //     // connection pool
  //     pool: { min: 0, max: 5 },
  //     // acquire connection timeout, millisecond
  //     acquireConnectionTimeout: 30000,
  //   },
  //   // load into app, default is open
  //   app: true,
  //   // load into agent, default is close
  //   agent: false,
  // };
  // add your config here
  config.middleware = [
  ];

  return config;
};
